package com.example.BOOK.data;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

public class CirleSpriter {
    float x,y,r,maxwidth,maxheigh;
    double direction;
    Bitmap bitmap;
    public CirleSpriter(float x,float y, float r,float maxwidth,float maxheigh,Bitmap bitmap){
        this.x=x;
        this.y=y;
        this.r=r;
        this.direction=Math.random();
        this.maxwidth=maxwidth;
        this.maxheigh=maxheigh;
        this.bitmap=bitmap;
    }
    public void draw(Canvas canvas){
        canvas.drawBitmap(bitmap,x,y,null);
    }
    public void move(){
        this.x+=20*Math.cos(direction);
        this.y+=20*Math.sin(direction);
        if(this.x<0)this.x+=maxwidth;
        if(this.y<0)this.y+=maxheigh;
        if(this.x>=maxwidth)this.x-=maxwidth;
        if(this.y>=maxheigh)this.y-=maxheigh;
    }

    public boolean isShoted(float touchedx, float touchedy) {
        double distance=(touchedx-this.x)*(touchedx-this.x)+(touchedy-this.y)*(touchedy-this.y);
        return (distance<r*r);

    }
}
